.TH std::is_constructible,std::is_trivially_constructible,std::is_nothrow_constructible 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::is_constructible,std::is_trivially_constructible,std::is_nothrow_constructible \- std::is_constructible,std::is_trivially_constructible,std::is_nothrow_constructible

.SH Synopsis
   Defined in header <type_traits>
   template< class T, class... Args > \fB(1)\fP \fI(since C++11)\fP
   struct is_constructible;
   template< class T, class... Args > \fB(2)\fP \fI(since C++11)\fP
   struct is_trivially_constructible;
   template< class T, class... Args > \fB(3)\fP \fI(since C++11)\fP
   struct is_nothrow_constructible;

   1) If T is an object or reference type and the variable definition T
   obj(std::declval<Args>()...); is well-formed, provides the member constant value
   equal to true. In all other cases, value is false.
   For the purposes of this check, the variable definition is never interpreted as a
   function declaration, and the use of std::declval is not considered an odr-use.
   Access checks are performed as if from a context unrelated to T and any of the types
   in Args. Only the validity of the immediate context of the variable definition is
   considered.
   2) Same as \fB(1)\fP, but the variable definition does not call any operation that is not
   trivial. For the purposes of this check, the call to std::declval is considered
   trivial.
   3) Same as \fB(1)\fP, but the variable definition is noexcept.

   If T or any type in the parameter pack Args is not a complete type, (possibly
   cv-qualified) void, or an array of unknown bound, the behavior is undefined.

   If an instantiation of a template above depends, directly or indirectly, on an
   incomplete type, and that instantiation could yield a different result if that type
   were hypothetically completed, the behavior is undefined.

   If the program adds specializations for any of the templates described on this page,
   the behavior is undefined.

.SH Member constants

   value    true if T is constructible from Args..., false otherwise
   \fB[static]\fP \fI(public static member constant)\fP

.SH Member functions

   operator bool converts the object to bool, returns value
                 \fI(public member function)\fP
   operator()    returns value
   \fI(C++14)\fP       \fI(public member function)\fP

.SH Member types

   Type       Definition
   value_type bool
   type       std::integral_constant<bool, value>

.SH Notes

   In many implementations, is_nothrow_constructible also checks if the destructor
   throws because it is effectively noexcept(T(arg)). Same applies to
   is_trivially_constructible, which, in these implementations, also requires that the
   destructor is trivial: GCC bug 51452 LWG issue 2116.

.SH Example


// Run this code

 #include <iostream>
 #include <type_traits>

 class Foo
 {
     int v1;
     double v2;
 public:
     Foo(int n) : v1(n), v2() {}
     Foo(int n, double f) noexcept : v1(n), v2(f) {}
 };

 int main()
 {
     auto is = [](bool o) { return (o ? "\\t" "is " : "\\t" "isn't "); };
     std::cout << "Foo ...\\n"
               << is(std::is_trivially_constructible_v<Foo, const Foo&>)
               << "Trivially-constructible from const Foo&\\n"
               << is(std::is_trivially_constructible_v<Foo, int>)
               << "Trivially-constructible from int\\n"
               << is(std::is_constructible_v<Foo, int>)
               << "Constructible from int\\n"
               << is(std::is_nothrow_constructible_v<Foo, int>)
               << "Nothrow-constructible from int\\n"
               << is(std::is_nothrow_constructible_v<Foo, int, double>)
               << "Nothrow-constructible from int and double\\n";
 }

.SH Output:

 Foo ...
         is Trivially-constructible from const Foo&
         isn't Trivially-constructible from int
         is Constructible from int
         isn't Nothrow-constructible from int
         is Nothrow-constructible from int and double

.SH See also

   is_default_constructible
   is_trivially_default_constructible
   is_nothrow_default_constructible   checks if a type has a default constructor
   \fI(C++11)\fP                            \fI(class template)\fP
   \fI(C++11)\fP
   \fI(C++11)\fP
   is_copy_constructible
   is_trivially_copy_constructible
   is_nothrow_copy_constructible      checks if a type has a copy constructor
   \fI(C++11)\fP                            \fI(class template)\fP
   \fI(C++11)\fP
   \fI(C++11)\fP
   is_move_constructible
   is_trivially_move_constructible    checks if a type can be constructed from an
   is_nothrow_move_constructible      rvalue reference
   \fI(C++11)\fP                            \fI(class template)\fP
   \fI(C++11)\fP
   \fI(C++11)\fP
                                      specifies that a variable of the type can be
   constructible_from                 constructed from or bound to a set of argument
   (C++20)                            types
                                      (concept)
